/// 俱乐部模型
class ClubModel {
  final String id;
  final String name;
  final String description;
  final String image;
  final String creatorId;
  final int maxMembers;
  final int currentMembers;
  final DateTime createdAt;
  final List<String> memberIds;

  ClubModel({
    required this.id,
    required this.name,
    required this.description,
    required this.image,
    required this.creatorId,
    required this.maxMembers,
    required this.currentMembers,
    required this.createdAt,
    required this.memberIds,
  });

  /// 从 JSON 创建俱乐部模型
  factory ClubModel.fromJson(Map<String, dynamic> json) {
    return ClubModel(
      id: json['id'] as String,
      name: json['name'] as String,
      description: json['description'] as String,
      image: json['image'] as String,
      creatorId: json['creatorId'] as String,
      maxMembers: json['maxMembers'] as int,
      currentMembers: json['currentMembers'] as int,
      createdAt: DateTime.parse(json['createdAt'] as String),
      memberIds: List<String>.from(json['memberIds'] as List),
    );
  }

  /// 转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'description': description,
      'image': image,
      'creatorId': creatorId,
      'maxMembers': maxMembers,
      'currentMembers': currentMembers,
      'createdAt': createdAt.toIso8601String(),
      'memberIds': memberIds,
    };
  }

  /// 复制俱乐部模型并修改部分属性
  ClubModel copyWith({
    String? id,
    String? name,
    String? description,
    String? image,
    String? creatorId,
    int? maxMembers,
    int? currentMembers,
    DateTime? createdAt,
    List<String>? memberIds,
  }) {
    return ClubModel(
      id: id ?? this.id,
      name: name ?? this.name,
      description: description ?? this.description,
      image: image ?? this.image,
      creatorId: creatorId ?? this.creatorId,
      maxMembers: maxMembers ?? this.maxMembers,
      currentMembers: currentMembers ?? this.currentMembers,
      createdAt: createdAt ?? this.createdAt,
      memberIds: memberIds ?? this.memberIds,
    );
  }

  @override
  String toString() {
    return 'ClubModel(id: $id, name: $name, creatorId: $creatorId)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is ClubModel && other.id == id;
  }

  @override
  int get hashCode => id.hashCode;
}

/// 俱乐部群聊消息模型
class ClubMessageModel {
  final String id;
  final String clubId;
  final String userId;
  final String content;
  final DateTime createdAt;

  ClubMessageModel({
    required this.id,
    required this.clubId,
    required this.userId,
    required this.content,
    required this.createdAt,
  });

  /// 从 JSON 创建消息模型
  factory ClubMessageModel.fromJson(Map<String, dynamic> json) {
    return ClubMessageModel(
      id: json['id'] as String,
      clubId: json['clubId'] as String,
      userId: json['userId'] as String,
      content: json['content'] as String,
      createdAt: DateTime.parse(json['createdAt'] as String),
    );
  }

  /// 转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'clubId': clubId,
      'userId': userId,
      'content': content,
      'createdAt': createdAt.toIso8601String(),
    };
  }

  /// 复制消息模型并修改部分属性
  ClubMessageModel copyWith({
    String? id,
    String? clubId,
    String? userId,
    String? content,
    DateTime? createdAt,
  }) {
    return ClubMessageModel(
      id: id ?? this.id,
      clubId: clubId ?? this.clubId,
      userId: userId ?? this.userId,
      content: content ?? this.content,
      createdAt: createdAt ?? this.createdAt,
    );
  }

  @override
  String toString() {
    return 'ClubMessageModel(id: $id, clubId: $clubId, userId: $userId)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is ClubMessageModel && other.id == id;
  }

  @override
  int get hashCode => id.hashCode;
}
